package com.sm.honkon.ui.fragment

import android.os.Bundle
import com.sm.honkon.R
import com.sm.honkon.app.base.BaseFragment
import com.sm.honkon.app.ext.goMain
import com.sm.honkon.databinding.FrgLoginBinding
import com.sm.honkon.ui.activity.MainActivity
import com.sm.honkon.ui.model.LoginViewModel
import kotlinx.android.synthetic.main.frg_login.*
import me.hgj.jetpackmvvm.ext.nav
import me.hgj.jetpackmvvm.ext.navigateAction

class LoginFragment:BaseFragment<LoginViewModel,FrgLoginBinding>() {
    override fun layoutId(): Int  = R.layout.frg_login

    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.model = mViewModel
        tv_login.setOnClickListener {
            mViewModel.login{
                (activity as MainActivity).curHandlerEntity.postValue(it)
                nav().goMain()
            }
        }
        tv_signup.setOnClickListener {
            if (mViewModel.adminLogin.get()) {
                nav().navigateAction(R.id.resetAdminFragment)
            } else {
                nav().navigateAction(R.id.resetFragment)
            }
        }
    }
}